<?php
namespace App\Libs\Common;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;


class ElementController extends Controller
{	



	public function test()
	{
		//$res=$this->checkUserInfo('陈萌昊','410426199604176051','6228482058735160471');

        $res=$this->FourcheckUserInfo('陈萌昊','410426199604176051','13311231513','6228482058735160471');

        print_r($res);
	}



    //三要素验证
	public function checkUserInfo($name,$idCard,$accountNo)
    {   
        header("Content-type: text/html; charset=utf-8");

        $param['name']=$name;
        $param['idCard']=$idCard;
        $param['accountNo']=$accountNo;

        //测试环境
        //$header['xa-key']='dAV+pcqBr4Rng6KhcxyWdfYWGhCP/VSXBDApMiKR/zo=';
        //$url='https://dev-debug.365dayservice.com:8044/credit-api/v1/accountInfoV2/checkNameIdCardAccountNumberV2';

        //生产环境
        $header['xa-key']='t1xwO2HLNwJMxLiTlecME/tt3o3lx9lXbiuzsKxiZ84=';
        $url='https://api.365dayservice.com:8044/credit-api/v1/accountInfoV2/checkNameIdCardAccountNumberV2';

        $param=json_encode($param,JSON_UNESCAPED_UNICODE);

        $result=$this->request_post($url,$param);

        return json_decode($result,true);
    }

    //四要素验证
    public function FourcheckUserInfo($name,$idCard,$phone,$accountNo)
    {   
        header("Content-type: text/html; charset=utf-8");

        $param['name']=$name;
        $param['idCard']=$idCard;
        $param['mobile']=$phone;
        $param['accountNo']=$accountNo;
        

        //测试环境
        //$header['xa-key']='dAV+pcqBr4Rng6KhcxyWdfYWGhCP/VSXBDApMiKR/zo=';
        //$url='https://dev-debug.365dayservice.com:8044/credit-api/v1/accountInfoV2/checkNameIdCardAccountNumberV2';

        //生产环境
        $header['xa-key']='t1xwO2HLNwJMxLiTlecME/tt3o3lx9lXbiuzsKxiZ84=';
        $url='https://api.365dayservice.com:8044/credit-api/v1/accountInfo/checkMobileNameIdCardAccountNumber';

        $param=json_encode($param,JSON_UNESCAPED_UNICODE);

        $result=$this->request_post($url,$param);

        //return json_decode($result,true);

        $res=json_decode($result,true);

        if($res["code"] == '2000' && $res["payload"]["checkResult"] == '1')
        {
            return true;
        }else{
            return false;
            //return array("code"=>$res["code"],"message"=>$res["payload"]["checkResult"]);
        }
    }


     private function request_post($url = '', $param = '') 
     {
            $ch = curl_init();//初始化curl

            curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
            curl_setopt($ch, CURLOPT_URL,$url);//抓取指定网页
            curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
            curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
            curl_setopt($ch, CURLOPT_POSTFIELDS,$param);
            curl_setopt($ch, CURLOPT_HTTPHEADER,array(
                    'Content-Type: application/json; charset=utf-8',
                    'xa-key:t1xwO2HLNwJMxLiTlecME/tt3o3lx9lXbiuzsKxiZ84='
                ));

            $data = curl_exec($ch);//运行curl
             
            if($data === false)
            {
                return  'Curl error: ' . curl_error($ch);
            }
            
            curl_close($ch);
            
            return $data;
       }

}